//必须存在

_.Module.define({
	path: "common/widget/Card",
	requires: [],
	sub: {
		_option: {},
		_j_card: null,
		_open_timer: null,
		_close_timer: null,
		_is_show: !1,
		_is_first_show: !0,
		_default_option: {
			content: "",
			arrow_dir: "down",
			arrow_pos: {},
			card_css: {
				width: 170,
				"z-index": 1001
			},
			arrow_req: !0,
			auto_positon: !1,
			event_target: null,
			offset: {
				x: 0,
				y: 0
			},
			card_leave_display: !1,
			card_hover_show: !0,
			card_leave_hide: !1,
			attr: "",
			clazz: "",
			wrap: $("body")
		},
		initial: function(t) {
			var i = this;
			i._option = $.extend(!0, {}, i._default_option, t), this._buildCard()
		},
		_buildCard: function() {
			var t = this._option,
				i = this._genericTpl(),
				e = t.wrap;
			this._j_card = $(i), this._j_card.find(".j_content").html(t.content), e.append(this._j_card), delete t.card_css.height, this._j_card.css(t.card_css), t.card_css.height = this._j_card.find(".j_content").outerHeight(!0), this._arrow = this._j_card.find(".j_ui_white_arrow"), void 0 === t.arrow_pos.left && (this._arrow_left = t.card_css.width / 2 - 10, this._arrow.css({
				left: this._arrow_left
			})), this._arrow.css(t.arrow_pos), t.arrow_req || this._j_card.find(".j_ui_white_arrow").hide(), t.auto_positon && this._autoPosition()
		},
		_autoPosition: function() {
			var t = this._option,
				i = {},
				e = $(window).height(),
				_ = $(window).width(),
				o = ($(document).scrollLeft(), $(document).scrollTop()),
				r = (t.event_target.innerWidth(), t.event_target.innerHeight()),
				s = "",
				a = {
					x: t.event_target.offset().left - t.card_css.width / 2 + t.event_target.outerWidth(!0) / 2,
					y: t.event_target.offset().top - t.card_css.height - 10,
					width: this._j_card.innerWidth(),
					height: this._j_card.innerHeight() + this._arrow.innerHeight()
				};
			i.left = a.x, i.top = a.y;
			var n = t.arrow_pos.left || this._arrow_left,
				d = 15,
				h = _;
			_ < $(document).width() && (h = $(document).width());
			var c = h - (t.card_css.width + d);
			i.left < d ? (n += i.left - d, i.left = d) : i.left > c && (n += i.left - c, i.left = c), i.top < o ? (s = "up", i.top += r + (a.height || 0), i.top -= t.offset.y) : (i.top += i.top + r > o + e ? -r - (a.height || 0) : 0, s = "down", i.top += t.offset.y), this._arrow.removeClass("ui_white_down").removeClass("ui_white_up").addClass("ui_white_" + s).css({
				left: n
			}), this._j_card.css(i)
		},
		_genericTpl: function() {
			var t = this._option.attr,
				i = this._option.arrow_dir,
				e = this._option.clazz,
				_ = ['<div class="ui_card_wrap ' + e + '" ' + t + ' style="visibility: hidden">', '<div class="j_content ui_card_content ">', "</div>", '<span class="j_ui_white_arrow arrow ui_white_' + i + '"></span>', "</div>"].join("");
			return _
		},
		showCard: function(t) {
			var i = this;
			i._close_timer && clearTimeout(i._close_timer), t && "delayShow" == t.type ? (i._open_timer && clearTimeout(i._open_timer), i._open_timer = setTimeout(function() {
				i._showCardDo()
			}, t.time)) : i._showCardDo()
		},
		closeCard: function(t) {
			var i = this;
			i._open_timer && clearTimeout(i._open_timer), t && "delayClose" == t.type ? i._close_timer = setTimeout(function() {
				i._closeCardDo()
			}, t.time) : i._closeCardDo()
		},
		hideCard: function(t) {
			var i = this;
			i._open_timer && clearTimeout(i._open_timer), t && "delayHide" == t.type ? i._close_timer = setTimeout(function() {
				i._hideCardDo()
			}, t.time) : i._hideCardDo()
		},
		_showCardDo: function() {
			var t = this;
			t._is_first_show && (this._j_card.bind("mouseenter", function() {
				t._option.card_hover_show && (t._is_show = !0)
			}), this._j_card.bind("mouseleave", function() {
				return t._option.card_leave_display ? !1 : (t._is_show = !1, t._option.card_leave_hide ? t.hideCard() : t.closeCard(), void 0)
			}), t._is_first_show = !1), this._j_card.css({
				visibility: "visible"
			})
		},
		_closeCardDo: function() {
			var t = this;
			this._j_card && !this._is_show && t._j_card.remove()
		},
		_hideCardDo: function() {
			var t = this;
			this._j_card && !this._is_show && t._j_card.css({
				visibility: "hidden"
			})
		},
		setContent: function(t) {
			var i = this._option;
			if(null !== this._j_card) {
				var e = this._j_card.find(".j_content");
				e.html(t), i.card_css.height = e.outerHeight(!0), this._j_card.css({
					height: i.card_css.height
				}), i.auto_positon && this._autoPosition()
			}
		}
	}
});